package com.xingkeduo.pojo.enums;

import com.xingkeduo.util.pojo.base.BaseEnum;
import lombok.extern.slf4j.Slf4j;

/**
 * @Description:
 * @Author:gaozifeng
 * @Date 2019/6/12 17:28
 **/
@Slf4j
public enum LoginEnums implements BaseEnum {
    //1微信授权 2手机号+验证码 3手机号+密码
    WECHAT(1, "微信授权"),
    PHONE_NUM(2, "手机号验证码"),
    PHONE_PASSWORD(3, "手机号密码");

    private int type;
    private String desc;

    private LoginEnums(int type, String desc) {
        this.type = type;
        this.desc = desc;
    }

    public int getType() {
        return type;
    }

    public LoginEnums setType(int type) {
        this.type = type;
        return this;
    }

    public String getDesc() {
        return desc;
    }

    public LoginEnums setDesc(String desc) {
        this.desc = desc;
        return this;
    }

    public static boolean validValue(String value) {
        int value_int = Integer.parseInt(value);
        return validValue(value_int);
    }

    public static boolean validValue(int value) {
        LoginEnums[] enums = LoginEnums.values();
        for (int i = 0; i < enums.length; i++) {
            log.info("enums"+enums[i].getType());
            log.info("value"+value);
            if (enums[i].getType() == value)
                return true;
        }
        return false;
    }

    public static LoginEnums getType(String value) {
        int value_int = Integer.parseInt(value);
        return getType(value_int);
    }

    public static LoginEnums getType(int value) {
        LoginEnums[] enums = LoginEnums.values();
        for (int i = 0; i < enums.length; i++) {
            log.info("enums"+enums[i].getType());
            log.info("value"+value);
            if (enums[i].getType() == value)
                return enums[i];
        }
        return null;
    }

    @Override
    public int getValue() {
        return 0;
    }
}
